package com.jxpowernode.bitcon.btcrpccode;

import com.alibaba.fastjson.JSONObject;
import com.jxpowernode.bitcon.Constants;
import com.jxpowernode.bitcon.bean.rpcbtc.GetDifficultyHash;
import com.jxpowernode.bitcon.request.HttpUtils;
import com.jxpowernode.bitcon.service.btcservice.GetBitconService;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Lixuewei
 * @Email:1410511702@qq.com
 * @Desc: 该类用户实现通过rpc访问调用btc的getDifficulty方法
 * @Date: 2021/12/16 15:53
 */
public class GetDifficulty {

    /**
     * 该方法用于获取区块取出难度值
     * @return 返回出块难度值
     */
   public GetDifficultyHash getDifficulty(){
       GetBitconService service = new GetBitconService();
       Map<String, String> bitcon = service.getBitcon();

       Map<String,Object> boby = new HashMap<String,Object>();
       boby.put("id","1001");
       boby.put("method","getdifficulty");
       byte[] data = JSONObject.toJSONBytes(boby);
       String result = HttpUtils.post(Constants.RPC_URL, bitcon, data);
       GetDifficultyHash getDifficultyHash = JSONObject.parseObject(result, GetDifficultyHash.class);
       return  getDifficultyHash;

   }
}
